<?php
/*
 * Author: Vuong Van Binh
 * Email : wanbin@vietnambiz.com
 */
//GET All CAT FAQ
function get_all_cat_faq(){

    global $db;
	
    $sql = "SELECT * FROM cat_faq WHERE lang='".$_SESSION["lang"]."' ORDER BY cat_id DESC";
	
	$qr=$db->query($sql);
	
	return $qr;
  
}
//GET CAT FAQ INFO
function get_cat_faq_by_id($id){

  global $db;

  $cat_faq_info = $db->query_first("SELECT * FROM cat_faq WHERE cat_id =".intval($id));

  return $cat_faq_info;
}
//GET CAT FAQ INFO
function get_cat_faq_by_link($name_link){

  global $db;

  $cat_faq_info = $db->query_first("SELECT * FROM cat_faq WHERE cat_name_link ='".mysql_real_escape_string($name_link)."'");

  return $cat_faq_info;
}
//GET FAQ INFO
function get_faq_info($name_link){

  global $db;

  $faq_info = $db->query_first("SELECT * FROM faq WHERE title_link ='".mysql_real_escape_string($name_link)."'");

  return $faq_info;
}
//GET ALL FAQ PAGE
function get_all_faq_page($cat_id=0,$page=1)
{

	global $db,$CONFIG;
	
	$condition="";
	
	if(intval($cat_id)>0){
		
		$condition = " AND faq.cat_id = ".intval($cat_id);
	
	}
	
	$sel_all=$db->query_first("SELECT COUNT(id) m FROM faq WHERE 1".$condition);
	
	$page=intval($page) ? intval($page) :1;
	$page=intval($page);
	if ($page<0) $page=1;
	$number=$sel_all['m']; 
	$limit = $CONFIG['rows_per_page_faq'];
	$total=ceil($number/$limit); 
	$start = (($page*$limit)-$limit);
	
	$faq = $db->query("SELECT faq.*,cat_faq.cat_name FROM faq,cat_faq WHERE 1".$condition." AND faq.lang='".$_SESSION["lang"]."' AND faq.cat_id = cat_faq.cat_id ORDER BY id DESC LIMIT ".$start.",".$limit);
	
	return array("faq"=>$faq,"page"=>$page,"total"=>$total);

}
//GET ALL FAQ PAGE
function get_other_faq($cat_id=0,$not_id)
{

	global $db,$CONFIG;
	
	$faq = $db->query("SELECT faq.*,cat_faq.cat_name FROM faq,cat_faq WHERE faq.cat_id = ".intval($cat_id)." AND faq.cat_id = cat_faq.cat_id AND id != ".intval($not_id)." ORDER BY id DESC LIMIT 0,".$CONFIG['rows_other_faq']);
	
	return $faq;

}
?>
